package com.huluobo.a2110mvpimdemo.conversation;

import android.util.Log;

import com.huluobo.a2110mvpimdemo.base.BasePresenter;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMConversation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by LC on 2023/12/22.
 */
public class ConversationPresenter extends BasePresenter<ConversationContract.View> implements ConversationContract.Presenter {
    @Override
    public void loadConversations() {
        //拿到所有会话列表的map,map中<K,V>结构的,包含了键和值
        Map<String, EMConversation> allConversations = EMClient.getInstance().chatManager().getAllConversations();
        //将map中所有的值保存到一个list中,这就是真实需要的数据源
        List<EMConversation> conversations = new ArrayList<>(allConversations.values());
        Log.i("TagA","conversations:"+conversations.size());
        if (conversations.size() == 0) {
            if (isAttach()) {
                getView().onLoadConversationsFailed("当前没有会话信息");
            }else {
                Log.i("TagA","size=0没有绑定视图");
            }
        } else {
            if (isAttach()) {
                getView().onLoadConversationsSuccess(conversations);
            }else {
                Log.i("TagA","size!=0没有绑定视图");
            }
        }
    }
}
